// Loesung_von_Aufgabe_2.5.7_5_Fahrrad

float w = -45; // Startwinkel in Grad
float rB; // Betrag von r
float MB; // Betrag des Drehmoments

void setup()
{
  size(500, 550);
}

void draw()
{
  background(255);

  w = w + 0.3;

  PVector r = new PVector(200*cos(radians(w)), 200*sin(radians(w)));
  rB = r.mag(); // Betrag von r

  translate(200, 250); // erste Verschiebung

  // Kette
  stroke(0);
  line(-200, -80, 0, -100);
  line(-200, 80, 0, 100);

  // Zahnrad
  stroke(0, 0, 255);
  strokeWeight(6);
  noFill();
  ellipse(0, 0, 200, 200);

  // Pedal
  noStroke();
  fill(150);
  rect(r.x-30, r.y-15, 60, 30);

  // Vektor r als Pedalstange
  stroke(0, 0, 180);
  strokeWeight(10);
  line(0, 0, r.x, r.y);

  translate(r.x, 0); // zweite Verschiebung

  PVector F = new PVector(0, 70); // Kraft auf das Trittpedal

  translate(0, r.y); // dritte Verschiebung

  // Vektor F wird gezeichnet
  stroke(255, 0, 0);
  strokeWeight(5);
  line(0, 0, F.x, F.y);
  noStroke();
  fill(255, 0, 0);
  triangle(F.x-10, F.y-10, F.x+10, F.y-10, F.x, F.y+20);

  PVector M = F.cross(r); // Drehmoment
  MB = M.mag(); // Betrag des Drehmomentes

  textSize(24);
  fill(0);
  text("w in Grad = " +round(w), -170-r.x, -200-r.y);
  fill(255, 0, 255);
  text("M in Nm = " +round(MB/1000), 60-r.x, -200-r.y);

  if (w >= 90)
  {
    noLoop();
  }
}